<!--区域管理-->
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<title>数据字典管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<!--查询条件-->
<div class="layui-collapse" id="search">
	<blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form" id="dataMoTable" lay-filter="dataMoTable">
	    <div class="layui-form-item">
	        <div class="layui-inline ">
                <label class="layui-form-label">数据描述：</label>
            	<div class="layui-input-inline">
            	    <select name="dateType" id="Motype" lay-filter="type">
                        <option value="0">请选择数据描述：</option>
                    </select>
            	</div>
            </div>
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                   <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub">查询</button>
                </div>
            </div>
        </div>
	</form>
	</blockquote>
</div>
<!--数据表格-->
<div>
    <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
    <div id="toolBars" style="display: none">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>添加</button>
    </div>
    <div id="rowBars" style="display: none">
        <button type="button" lay-event="show" class="layui-btn layui-btn-sm layui-btn-warm"><span class="layui-icon layui-icon-search"></span>查看</button>
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm layui-bg-green"><span class="layui-icon layui-icon-edit"></span>修改</button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span>删除</button>
    </div>
</div>
<!--添加修改弹出层-->
<div id="addOrUpdate" style="display: none">
    <form class="layui-form" id="addOrUpdateTable" lay-filter="addOrUpdateTable">
	    <div class="layui-form-item">
	        <div class="layui-block ">
                <label class="layui-form-label">数据描述：</label>
            	<div class="layui-input-block">
            	    <input type="hidden" name="id">
            	    <input name="dateDescription" type="text" lay-verify="required" class="layui-input searchVal" lay-filter="areaName">
            	</div>
            </div>
            <div class="layui-block ">
                <label class="layui-form-label">数据内容：</label>
            	<div class="layui-input-block">
            	    <input name="dataName" type="text" lay-verify="required" class="layui-input searchVal" lay-filter="areaName">
            	</div>
            </div>
            <br>
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                   <button type="submit" class="layui-btn" lay-submit="" lay-filter="search">提交</button>
                </div>
            </div>
        </div>
	</form>
</div>
<!--查看弹出层-->
<div id="show" style="display: none">
    <form class="layui-form" id="showTable" lay-filter="showTable">
	    <div class="layui-form-item">
	        <div class="layui-block ">
                <label class="layui-form-label">数据内容：</label>
            	<div class="layui-input-block">
            	    <input type="hidden" name="id">
            	    <input name="dataName" type="text" readonly lay-verify="required" class="layui-input searchVal" >
            	</div>
            </div>
            <br>
            <div class="layui-block ">
                <label class="layui-form-label">数据编号：</label>
            	<div class="layui-input-block">
            		<input name="dataNum" type="text" readonly lay-verify="required" class="layui-input searchVal">
            	</div>
            </div>
            <br>
            <div class="layui-block ">
                <label class="layui-form-label">数据描述：</label>
            	<div class="layui-input-block">
            	    <input name="dateDescription" readonly type="text" lay-verify="required" class="layui-input searchVal">
            	</div>
            </div>
            <div class="layui-block ">
                <label class="layui-form-label">描述编号：</label>
            	<div class="layui-input-block">
            	    <input name="dateType" type="text" readonly lay-verify="required" class="layui-input searchVal">
            	</div>
            </div>
        </div>
	</form>
</div>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script>
    layui.use(['form','element','layer','jquery','table'],function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;
        //数据描述
        $.post("/getDataDescription",function(data) {
            var html = '<option value="0">请选择数据描述：</option>';
            $.each(data,function(index,item) {
                html += "<option value='"+item.dateType+"'>"+item.dateDescription+"</option>";
            })
            $("#Motype").html(html);
            form.render('select');
        });
        var tableIns = table.render({
            elem:"#dataTable",
            url:"/loadData",
            toolbar:"#toolBars",
            page:true,
            height:'full',
            cols:[
                [
                    {type:'checkbox',fixed:'center'}
                    ,{field:'id', title:'ID',  fixed: 'left', unresize: true,width:'80' ,sort: true,align:'center'}
                    ,{field:'dataName', title:'数据内容',align:'center',width:'180'}
                    ,{field:'dataNum', title:'数据编号',align:'center',width:'150'}
                    ,{field:'dateDescription', title:'数据描述',align:'center',width:'150'}
                    ,{field:'dateType', title:'描述编号',align:'center',width:'150'}
                    ,{fixed: 'right', title:'操作', toolbar: '#rowBars',width:260}
                ]
            ]
        })
        //模糊表单提交
        form.on("submit(sub)",function(data) {
            tableIns.reload({
                where:data.field
            })
            return false;
        })
        var mainIns;
        var url;
        //监听头部工具栏事件
        table.on('toolbar(dataTable)',function(obj) {
            switch (obj.event) {
                case 'add':
                    openAdd();
            }
        });
        //监听行工具栏事件
        table.on('tool(dataTable)',function(obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'show':
                    openShow(data);
                    break;
                case 'update':
                    openUpdate(data);
                    break;
                case 'delete':
                    openDelete(data);
            }
        });
        //提交表单
        form.on('submit(search)',function() {
            var params = $("#addOrUpdateTable").serialize();
            $.post(url,params,function(data) {
                //提示信息
                layer.msg(data.msg);
                //关闭弹出层
                layer.close(mainIns);
                //重新渲染table
                tableIns.reload();
            })
            return false;
        });
        //关闭弹出层
        form.on('submit(close)',function() {
            var params = $("#addOrUpdateTable").serialize();
            $.post(url,params,function(data) {
                //关闭弹出层
                layer.close(mainIns);
            })
            return false;
        });
        //打开添加弹出层
        function openAdd() {
            mainIns = layer.open({
                type:1,
                content:$("#addOrUpdate"),
                area:['600px','280px'],
                title:"添加采购单",
                success:function(layero,index) {
                    //更改url
                    url = "/add";
                    $("#addOrUpdateTable")[0].reset();

                }
            })
        }
        //打开修改弹出层
        function openUpdate(data) {
            url = "/update";
            mainIns = layer.open({
                type:1,
                content:$("#addOrUpdate"),
                area:['600px','280px'],
                title:"查看采购单",
                success:function(index) {
                    console.log(data);
                    form.val("addOrUpdateTable",data);
                }
            })
        }

        //打开查看弹出层
        function openShow(data) {
            mainIns = layer.open({
                type:1,
                content:$("#show"),
                area:['600px','280px'],
                title:"查看采购单",
                success:function(index) {
                    console.log(data);
                    form.val("showTable",data);
                }
            })
        }
        //打开删除弹出层
        function openDelete(data) {
            mainIns = layer.confirm('您真的要删除吗？', {
                btn: ['删除','取消'] //按钮
            }, function(){
                $.post("/delete",{id:data.id},function(res) {
                    layer.msg(res.msg);
                    tableIns.reload();
                })
            })
        }

    })
</script>
</body>
</html>